import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart' show timeDilation;

import 'AnimatedListDemo.dart';
import 'StaggeredAnimation.dart';
import 'animated_widget/scale_and_rotate.dart';
import 'flare/penguin_dance.dart';
import 'flare/space_reload/main.dart';
import 'flare/teddy/main.dart';
import 'sequential_animation.dart';

void main() {
  runApp(MaterialApp(
    home: Scaffold(
      appBar: AppBar(
        title: const Text(
          "animation demo",
        ),
      ),
      body: _Body(),
    ),
    routes: {
      "animated_widget": (ctx) => ScalePage(),
      "staggered_animation": (ctx) => ImagesDemo(),
      "sequential_animation": (ctx) => StaggerDemo(),
      "animated_list": (ctx) => AnimatedListDemo(),
      "flare_teddy": (ctx) => Teddy(),
      "flare_refresh": (ctx) => SpaceReload(),
      "flare_penguin_dance": (ctx) => PenguinDance(),
    },
  ));
}

class _Body extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return SizedBox.expand(
        child: Column(
      children: <Widget>[
        _getButton('animted_widget', () {
          timeDilation = 1;
          Navigator.of(context).pushNamed("animated_widget");
        }),
        _getButton('staggered_animation', () {
          timeDilation = 1;
          Navigator.of(context).pushNamed("staggered_animation");
        }),
        _getButton('sequential_animation', () {
          timeDilation = 1;
          Navigator.of(context).pushNamed("sequential_animation");
        }),
        _getButton('animated_list', () {
          timeDilation = 1;
          Navigator.of(context).pushNamed("animated_list");
        }),
        _getButton('flare_teddy', () {
          timeDilation = 1;
          Navigator.of(context).pushNamed("flare_teddy");
        }),
        _getButton('flare_refresh', () {
          timeDilation = 1;
          Navigator.of(context).pushNamed("flare_refresh");
        }),
        _getButton('flare_penguin_dance', () {
          timeDilation = 1;
          Navigator.of(context).pushNamed("flare_penguin_dance");
        }),
      ],
    ));
  }

  _getButton(String content, void callback()) {
    return Padding(
        padding: EdgeInsets.all(10),
        child: RaisedButton(
          child: Text(content ?? "error"),
          onPressed: callback,
        ));
  }
}
